package com.sdonkey.score.log;

import java.util.Date;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author 赵超
 */
@Aspect
public class LogsCollectionAOP {

	@Pointcut("execution(* com.sdonkey.score.controller.*.*(..))")
	public void controllerAspect() {
	}

	@Pointcut("@annotation(com.sdonkey.score.log.Log)")
	public void logAspect() {
	}

	@Around(value = "logAspect()")
	public Object log(ProceedingJoinPoint pjp) throws Throwable {
		long time = new Date().getTime();
		// 获取方法名
		System.out.println("方法名称： " + pjp.getSignature().getName());
		// 获取参数
		Object[] args = pjp.getArgs();
		System.out.println("参数数量： " + args.length);
		int i = 0;
		for (Object object : args) {
			i++;
			System.out.println("参数列表： " + i + "  " + object);
		}
		Object proceed = pjp.proceed(args);
		long time2 = new Date().getTime();
		System.out.println("返回值： " + proceed);
		System.out.println("执行时间： " + (time2 - time) + "ms");
		return proceed;
	}

}
